package api

import (
	"banke/utile"
	"net/http"

	"github.com/gin-gonic/gin"
)

// 获取快递数据
func getExpressageData(c *gin.Context) {

	// 响应信息
	c.JSON(http.StatusOK, gin.H{
		"status":         1,
		"ExpressageData": utile.GetExpressageData(),
		"message":        "Get express information successful",
	})
}


type SaveDataRequest struct {
	TrickingNumber   string `json:"tricking_number"`
	TrickingLocation string `json:"tricking_location"`
}

func SaveData(c *gin.Context) {
	var requestData SaveDataRequest
	if err := c.ShouldBindJSON(&requestData); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"status": 0,
			"error":  err.Error(),
		})
		return
	}

	// 更新数据库中的快递信息
	if err := utile.UpdateExpressageLocation(requestData.TrickingNumber, requestData.TrickingLocation); err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"status": 0,
			"error":  "Failed to update location",
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"status":  1,
		"message": "Location updated successfully",
	})
}
